package com.jumi.microservice.state;

import com.jumi.microservice.constant.GoodsStatus;
import com.jumi.microservice.domain.GoodsDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 商品状态工厂
 *
 * @author Administrator
 */
@Component
public class GoodsStateFactory {

    /**
     * 默认商品状态
     */
    @Autowired
    private DefaultGoodsState defaultGoodsState;
    /**
     * 上架状态
     */
    @Autowired
    private PuttedOnShelvesGoodsState puttedOnShelvesGoodsState;
    /**
     * 下架状态
     */
    @Autowired
    private PulledOffShelvesGoodsState pulledOffShelvesGoodsState;

    /**
     * 定时上架状态
     */
    @Autowired
    private TimingPuttedOnShelvesGoodsState timingPuttedOnShelvesGoodsState;

    /**
     * 获取商品对应的状态组件
     *
     * @param goods 商品
     * @return 状态组件
     * @throws Exception
     */
    public GoodsState get(GoodsDTO goods) {
        if (GoodsStatus.PULLED_OFF_SHELVES.getCode().equals(goods.getGoodsState())) {
            return pulledOffShelvesGoodsState;
        } else if (GoodsStatus.PUTTED_ON_SHELVES.getCode().equals(goods.getGoodsState())) {
            return puttedOnShelvesGoodsState;
        } else if (GoodsStatus.FIX_PUTTED_ON_SHELVES.getCode().equals(goods.getGoodsState())) {
            return timingPuttedOnShelvesGoodsState;
        } else {
            return defaultGoodsState;
        }
    }
}
